/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package sport;

import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.rmi.PortableRemoteObject;
import player.BasketballPlayer;
import player.FootballPlayer;
import player.HockeyPlayer;
import player.Player;
import player.PlayerHome;

/**
 *
 * @author denaas
 */
public class PlayerHomeFabric {
    public static PlayerHome getInstance(Integer sportId) throws NamingException {
        InitialContext ic = new InitialContext();
        Object objRef = null;
        switch (sportId.intValue()) {
            case 1:
                objRef = ic.lookup("ejb/player/FootballPlayer");
                break;
            case 2:
                objRef = ic.lookup("ejb/player/BasketballPlayer");
                break;
            case 3:
                objRef = ic.lookup("ejb/player/HockeyPlayer");
                break;
        }
        return (PlayerHome)PortableRemoteObject.narrow(objRef, PlayerHome.class);
    }
    
    public static PlayerHome getInstance(Player player) throws NamingException {
        InitialContext ic = new InitialContext();
        Object objRef = null;
        if (player instanceof FootballPlayer) {
            objRef = ic.lookup("ejb/player/FootballPlayer");
        } else if (player instanceof BasketballPlayer) {
            objRef = ic.lookup("ejb/player/BasketballPlayer");
        } else if (player instanceof HockeyPlayer) {
            objRef = ic.lookup("ejb/player/HockeyPlayer");
        }
        return (PlayerHome)PortableRemoteObject.narrow(objRef, PlayerHome.class);
    }
}
